
** set path
// gl path ""

** open log
cap log close
log using "$path/table_a5.log", replace

use "$path/foreclosures_analysis.dta", clear

sort fips year
by fips: gen foreclosure_lead = foreclosure_rate[_n+1]
compress

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs foreclosure_rate foreclosure_inc foreclosure_lead [aw=pop_y], a(fips sy) cluster(fips)
local b1 = _b[foreclosure_rate]
local se1 = _se[foreclosure_rate]
local bint1 = _b[foreclosure_inc]
local seint1 = _se[foreclosure_inc]
local b1_2 = _b[foreclosure_lead]
local se1_2 = _se[foreclosure_lead]
local n1 = e(N)
local nclust1 = e(N_clust)

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs foreclosure_rate foreclosure_inc foreclosure_lead [aw=pop_y], a(fips popyear) cluster(fips)
local b2 = _b[foreclosure_rate]
local se2 = _se[foreclosure_rate]
local bint2 = _b[foreclosure_inc]
local seint2 = _se[foreclosure_inc]
local b2_2 = _b[foreclosure_lead]
local se2_2 = _se[foreclosure_lead]
local n2 = e(N)
local nclust2 = e(N_clust)

log close


quietly {
	cap log close
	set linesize 255
	log using "$path/parallel_trends_test.tex", text replace
	
	noisily dis "\begin{table}[h]"
	noisily dis "\centering"
	noisily dis "\caption{\textbf{Effects of Future Foreclosures on Current Presidential Elections, Parallel Trends Test, 2004--2012.}"
	noisily dis "\label{tab:parallel_trends_test}}"
	noisily dis "\begin{tabular}{lcc}"
	noisily dis "\toprule \toprule"
	noisily dis " & \multicolumn{2}{c}{Dem Pres Vote Pct (0-100)}\\"
	noisily dis " & (1) & (2) \\"
	noisily dis "\midrule"
	noisily dis "Foreclosures Per 1,000 People & " %4.2f `b1' " & " %4.2f `b2'  "\\"
	noisily dis " & (" %4.2f `se1' ") & (" %4.2f `se2' ") \smallskip\\"
	noisily dis "Foreclosures $ \times $ Inc. Party &  " %4.2f `bint1' " & " %4.2f `bint2'  "\\"
	noisily dis " & (" %4.2f `seint1' ") & (" %4.2f `seint2' ")  \medskip \\"
	noisily dis "Foreclosures ( $ t+1 $ ) &  " %4.2f `b1_2' " & " %4.2f `b2_2'  "\\"
	noisily dis " & (" %4.2f `se1_2' ") & (" %4.2f `se2_2' ")  \medskip \\"

	noisily dis " N & " %4.0fc `n1' " & " %4.0fc `n2'  " \\ "
	noisily dis " \# Counties & "  %4.0fc `nclust1' " & " %4.0fc `nclust2'  " \\ "
	noisily dis "State-Year Fixed Effects & Y & Y  \\"
	noisily dis "Pop Decile-Year Fixed Effects & N & Y \\"
	noisily dis " Population Weights & Y & Y  \\"
	noisily dis "\bottomrule \bottomrule"
	noisily dis "\multicolumn{3}{p{.55\textwidth}}{\footnotesize Standard errors generated from 1,000 iterations of a county-level block bootstrap procedure. "
	noisily dis "Inc Party is 1 for Dem, -1 for Rep. Main effect for Inc Party is absorbed by fixed effects.}"
	noisily dis "\end{tabular}"
	noisily dis "\end{table}"
	
	log off
	
}
